package com.mew.auc.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;

@Component
public class AesUtil {
    private static final String KEY = "Fd+0jder2341%&*!";
    private AES aes;

    @PostConstruct
    public void init(){
        aes = SecureUtil.aes(KEY.getBytes(StandardCharsets.UTF_8));
    }

    public String encrypt(String src) throws Exception {


        return aes.encryptBase64(src);
    }

    public String decrypt(String src) throws Exception {

        byte[] raw = Base64.decode(src.getBytes(StandardCharsets.UTF_8));
        return aes.decryptStr(raw);
    }
}

